//
//  CXChangeColorViewController.m
//  GiftThat
//
//  Created by ChuXiang on 16/1/16.
//  Copyright © 2016年 ChuXiang. All rights reserved.
//

#import "CXChangeColorViewController.h"
#import "CXChangeColorCollectionViewCell.h"


@interface CXChangeColorViewController () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *changeColorCollect;
@property (nonatomic, strong) NSArray *array;
@property (nonatomic, strong) NSArray *labelArray;
@property (nonatomic, strong) NSIndexPath *oldIndex;
@end


static NSString *indetifier = @"ChangeColorIdentifier";
static NSString *heardIdentifier = @"downHeadViewIdentifier";
@implementation CXChangeColorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"主题换肤";
    self.array = [[NSArray alloc] initWithObjects:@"redColor", @"greenColor", @"orangeColor", @"pinkColor", @"blackColor", nil];
    self.labelArray = [[NSArray alloc] initWithObjects:@"官方红", @"官方绿", @"官方橙", @"官方粉", @"官方黑", nil];
    self.oldIndex = [NSIndexPath indexPathForRow:0 inSection:0];
    [self createCollection];
    


}

//- (void) changeDay:(NSNotification *)message {
//    if ([message.object isEqualToString:@"Night"]) {
//        self.myTable.backgroundColor = [UIColor colorWithRed:35 / 255.0 green:34 / 255.0 blue:38 / 255.0 alpha:1.0];
//        self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
//    }else {
//        self.myTable.backgroundColor = [UIColor whiteColor];
//        self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:232 / 255.0 green:17 / 255.0 blue:19 / 255.0 alpha:1.0];
//    }
//    [self.myTable reloadData];
//}


- (void)createCollection {
    
    
    UICollectionViewFlowLayout *flowlaout = [[UICollectionViewFlowLayout alloc] init];
    flowlaout.itemSize = CGSizeMake(self.view.width / 3, self.view.height / 2 - self.view.height / 6);
    flowlaout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.changeColorCollect = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height / 2) collectionViewLayout:flowlaout];
    self.changeColorCollect.backgroundColor = [UIColor whiteColor];
    [self.changeColorCollect registerClass:[CXChangeColorCollectionViewCell class] forCellWithReuseIdentifier:indetifier];

    self.changeColorCollect.delegate = self;
    self.changeColorCollect.dataSource = self;
    [self.view addSubview:self.changeColorCollect];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, (self.view.width - 40) / 2 - 40, 30)];
    label.text = @"主题换肤";
    [label setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:15]];
    label.textColor = [UIColor blackColor];
    [self.view addSubview:label];

}

- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CXChangeColorCollectionViewCell *item = [collectionView dequeueReusableCellWithReuseIdentifier:indetifier forIndexPath:indexPath];
//    [item setMutableArray:self.array WithLabelArray:self.labelArray];
    [item setMutableArray:self.array[indexPath.item] WithLabelArray:self.labelArray[indexPath.item]];
    
    return item;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.item == 0) {
        [[NSUserDefaults standardUserDefaults] setObject:@"RedColor" forKey:@"Color"];
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center postNotificationName:@"Color" object:@"RedColor" userInfo:nil];
    }else if (indexPath.item == 1) {
        [[NSUserDefaults standardUserDefaults] setObject:@"GreenColor" forKey:@"Color"];
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center postNotificationName:@"Color" object:@"GreenColor" userInfo:nil];
    }else if (indexPath.item == 2) {
        [[NSUserDefaults standardUserDefaults] setObject:@"OrangeColor" forKey:@"Color"];
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center postNotificationName:@"Color" object:@"OrangeColor" userInfo:nil];
    }else if (indexPath.item == 3) {
        [[NSUserDefaults standardUserDefaults] setObject:@"PinkColor" forKey:@"Color"];
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center postNotificationName:@"Color" object:@"PinkColor" userInfo:nil];
    }else if (indexPath.item == 4) {
        
        [[NSUserDefaults standardUserDefaults] setObject:@"BlackColor" forKey:@"Color"];
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center postNotificationName:@"Color" object:@"BlackColor" userInfo:nil];
        
    }

    UIAlertController *mBoxView = [UIAlertController alertControllerWithTitle:@"嗨" message:[NSString stringWithFormat:@"您已选中%@", self.labelArray[indexPath.item]] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        [self dismissViewControllerAnimated:YES completion:^{

        }];
    }];
    
    [mBoxView addAction:cancelAction];
    [self presentViewController:mBoxView animated:YES completion:nil];

    
}



#pragma mark - 内存泄露
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
